package com.godyao.handler;

import com.godyao.enums.ResultMsg;
import com.godyao.utils.ResponseUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 认证失败会走这个处理器
 * @author godyao
 * @date 2022/3/16
 */
@Component
public class EntryPointUnauthorizedHandler2 implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException {
        ResponseUtils.result(httpServletResponse, new ResultMsg(403, "认证失败", null));

    }
}
